/*
pinia:
 1:下载
 2：在main.js中导入挂载
 3：定义模块
 4：使用模块
*/
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
// use+模块名+Store  推荐命名
export const useUserStore = defineStore(
  'user',
  () => {
    // 没有setup语法糖的setup函数
    // state ,getters,actions
    const num = ref(10)
    const getNum = computed(() => {
      return '数量:' + num.value
    })
    const setNum = val => {
      num.value = val
    }
    const count = ref(999)
    const setCount = () => {
      count.value++
    }

    return { num, getNum, setNum, count, setCount }
  },
  {
    // 配制项
    // persist: true
    persist: {
      paths: ['count']
    }
  }
)
